﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BPM.Common;

namespace BPM.Entity
{
	public class Barcode : BaseEntity
	{
		private ILazyEntityRef<BarcodeCategory> _BarcodeCategory;
		/// <summary>
		/// 条码类别 (操作条码,权限条码,物料条码等)
		/// </summary>
		public BarcodeCategory BarcodeCategory
		{
			get
			{
				return this._BarcodeCategory.Entity;
			}
			set
			{
				this._BarcodeCategory.Entity = value;
			}
		}
		/// <summary>
		/// 所属类别Id
		/// </summary>
		public int BarcodeCategoryId
		{
			get
			{
				return this._BarcodeCategory.Id;
			}
			set
			{
				this._BarcodeCategory.Id = value;
			}
		}

		/// <summary>
		/// 条码编号
		/// </summary>
		public string Number { get; set; }

		public Barcode()
		{
			this._BarcodeCategory = this.CreateReference<BarcodeCategory>();
		}

		public override Result Validate()
		{
			if (this.Number == null || this.Number.Length != 13)
			{
				return "条码长度必须等于13。";
			}

			return base.Validate();
		}
	}
}